package com.efounder.activity.Order;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import com.efounder.adapter.BaseAdapter;
import com.efounder.bean.OrderInfoBean;
import com.efounder.holder.BaseHolder;
import com.efounder.holder.CreateOrderHolder;
import com.efounder.holder.OrderStoreInfoHolder;
import com.efounder.mobilemall.R;

import java.util.List;

/**
 * Created by Marcello on 2018/9/17.
 */
public class CreateOrderAdapter extends BaseAdapter<OrderInfoBean.DataBean.ShopsBean, OrderStoreInfoHolder> {

    private static final int ORDER_BODY = 0x001;
    private static final int ORDER_TITLE = 0x002;
    private static final int ORDER_STORE_INFO = 0x003;
    private RecyclerView.RecycledViewPool viewPool;

    /**
     * 设置数据,并设置点击回调接口
     *
     * @param list 数据集合
     */
    public CreateOrderAdapter(@Nullable List<OrderInfoBean.DataBean.ShopsBean> list) {
        super(list);
        viewPool = new RecyclerView.RecycledViewPool();
    }

    @Override
    public OrderStoreInfoHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new OrderStoreInfoHolder(parent, R.layout.item_order_store_info);
    }


    @Override
    public void onBindViewHolder(final OrderStoreInfoHolder holder, final int position) {
        super.onBindViewHolder(holder, position);
        onHolderClick(holder, position);

    }

    private void onHolderClick(final OrderStoreInfoHolder holder, final int position) {
        holder.getOrder_rlv_goods().setRecycledViewPool(viewPool);
//        TextView tvShippingFee = holder.getTvShippingFee();
//        if (tvShippingFee!=null) {
//            tvShippingFee.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    if(mOnOrderStoreInfoHolderListener!=null){
//                        mOnOrderStoreInfoHolderListener.onSelectExpress(v,position);
//                    }
//                }
//            });
//        }
        OrderGoodAdapter adapter = holder.getAdapter();
        if (adapter != null) {
            adapter.setOnItemClickListener(new OnItemClickListener<CreateOrderHolder>() {
                @Override
                public void onItemClick(CreateOrderHolder createOrderHolder, int pos) {
                    if (mOnOrderStoreInfoHolderListener != null) {
                        mOnOrderStoreInfoHolderListener.onChildItemClick(createOrderHolder, pos, position);
                    }

                }

                @Override
                public void onItemLongClick(CreateOrderHolder createOrderHolder, int pos) {

                }
            });
        }

    }

    public interface OnOrderStoreInfoHolderListener { //方便扩展


        void onSelectExpress(View v, int position);//邮寄方式选择

        void onChildItemClick(BaseHolder holder, int childPos, int pos);

    }

    private OnOrderStoreInfoHolderListener mOnOrderStoreInfoHolderListener;

    public void setOnOrderStoreInfoHolderListener(OnOrderStoreInfoHolderListener mOnOrderStoreInfoHolderListener) {
        this.mOnOrderStoreInfoHolderListener = mOnOrderStoreInfoHolderListener;
    }
}
